<!--
 * @Author: boyyang
 * @Date: 2022-02-11 14:23:00
 * @LastEditTime: 2022-02-11 14:23:00
 * @LastEditors: boyyang
 * @Description: 
 * @FilePath: \boyyang\plugin\boyyangUI\background\index.vue
-->


<template>
    <div class="background">
        <img :src="props.url" v-if="!props.isVideo" />
        <video :src="props.url" muted loop autoplay v-else></video>
        <div class="background-content">
            <slot></slot>
        </div>
    </div>
</template>

<script lang="ts" setup>
interface IBackgroundProps {
    url?: string; // 图片链接 or 视频链接
    isVideo?: boolean; // 是否是视频
}

const props = withDefaults(defineProps<IBackgroundProps>(), {
    url: '',
    isVideo: false
})
</script>

<style scoped lang="scss">
.background {
    box-sizing: border-box;
    width: 100%;
    height: 100%;

    background-image: url("@/assets/pix1001_4.jpg");
    background-size: cover;
    background-position: center;

    overflow: hidden;

    img,
    video {
        position: absolute;
        top: 0;
        left: 0;

        width: 100%;
        height: 100%;
        object-fit: cover;
        z-index: 1;
    }

    .background-content {
        width: 100%;
        height: 100%;
        z-index: 5;
        position: absolute;
        top: 0;
        left: 0;
    }
}
</style>
